package com.yun.web;

import com.yun.pojo.User;
import com.yun.service.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/login")
public class addServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取请求参数
        String username = request.getParameter("username");
        String code = request.getParameter("code");
        String pwd = request.getParameter("password");
        String add = request.getParameter("address");
        User user = new User(username,code,pwd,add);

        UserServiceImp serviceImp = new UserServiceImp();
        int i = serviceImp.addUser(user);
        if(i>0){//注册成功！
            request.getRequestDispatcher("/jsp/login.jsp").forward(request,response);
        }else {
            System.out.println("添加会员失败！！");
        }
    }
}
